package cn.com.nes.site.entity.dto;

import cn.hutool.core.util.ObjectUtil;

import java.util.List;

/**
 * @author yueb
 * @date 2019-09-03 15:36
 */

public class FunctionDataDto {

    private String functionCode;
    private String functionName;
    private String sblxId;
    private Integer functionType;
    private Object fieldValue;
    private String field;
    private Double MaxValue = 0d;
    private Double MinValue = 0d;
    private List<ResultCodeDto> listVal;
    private String unitValue;

    public String getFunctionCode() {
        return functionCode;
    }

    public void setFunctionCode(String functionCode) {
        this.functionCode = functionCode;
    }

    public String getFunctionName() {
        return functionName;
    }

    public void setFunctionName(String functionName) {
        this.functionName = functionName;
    }

    public String getSblxId() {
        return sblxId;
    }

    public void setSblxId(String sblxId) {
        this.sblxId = sblxId;
    }

    public Integer getFunctionType() {
        return functionType;
    }

    public void setFunctionType(Integer functionType) {
        this.functionType = functionType;
    }

    public Object getFieldValue() {
        return fieldValue;
    }

    public void setFieldValue(Object fieldValue) {
        this.fieldValue = fieldValue;
    }

    public String getField() {
        return field;
    }

    public void setField(String field) {
        this.field = field;
    }

    public Double getMaxValue() {
        return MaxValue;
    }

    public void setMaxValue(Double maxValue) {
        MaxValue = maxValue;
    }

    public Double getMinValue() {
        return MinValue;
    }

    public void setMinValue(Double minValue) {
        MinValue = minValue;
    }

    public List<ResultCodeDto> getListVal() {
        return listVal;
    }

    public void setListVal(List<ResultCodeDto> listVal) {
        this.listVal = listVal;
    }

    public String getUnitValue() {
        return unitValue;
    }

    public void setUnitValue(String unitValue) {
        this.unitValue = unitValue;
    }

    public void setMaxValue(Double maxValue, Object fieldValue) {
        try {
            if (ObjectUtil.isNotNull(maxValue)) {
                this.MaxValue = maxValue;
            } else if (ObjectUtil.isNotNull(this.functionType) && this.functionType == 3 && ObjectUtil.isNotNull(fieldValue)) {
                double v = Double.parseDouble((String) fieldValue);
                if (Math.abs(v) > 70) {
                    this.MaxValue = 65535d;
                } else {
                    this.MaxValue = 70d;
                }
            } else {
                this.MaxValue = 70d;
            }
        } catch (NumberFormatException e) {
            this.MaxValue = 65535d;
        }
    }

    public void setMinValue(Double minValue, Object fieldValue) {
        try {
            if (ObjectUtil.isNotNull(minValue)) {
                this.MinValue = minValue;
            } else if (ObjectUtil.isNotNull(this.functionType) && this.functionType == 3 && ObjectUtil.isNotNull(fieldValue)) {
                double v = Double.parseDouble((String) fieldValue);
                if (Math.abs(v) > 70) {
                    this.MinValue = -65535d;
                } else {
                    this.MinValue = 0d;
                }
            } else {
                this.MinValue = 0d;
            }
        } catch (NumberFormatException e) {
            this.MinValue = -65535d;
        }
    }
}
